package com.xuanyuan.base.listener;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import com.xuanyuan.base.BuildConfig;
import com.xuanyuan.base.utils.LogUtil;
import com.xuanyuan.base.helper.ActivityController;

/**
 * @author ken.luo
 * @version V1.0
 * @FileName:
 * @Description:
 * @date 2023/4/4
 * @email 424533553@qq.com
 */
public class ActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {

    @Override
    public void onActivityCreated(final Activity activity, final Bundle savedInstanceState) {
        ActivityController.INSTANCE.addActivity(activity);
        if (BuildConfig.DEBUG) {
            LogUtil.d(this, activity.getLocalClassName() + ".onActivityCreated");
        }
        initActivityUseTime(activity);
    }

    @Override
    public void onActivityStarted(final Activity activity) {
        if (BuildConfig.DEBUG) {
            LogUtil.d(this, activity.getLocalClassName() + ".onActivityStarted");
        }
    }

    @Override
    public void onActivityResumed(final Activity activity) {
        if (BuildConfig.DEBUG) {
            LogUtil.d(this, activity.getLocalClassName() + ".onActivityResumed");
        }
    }

    @Override
    public void onActivityPaused(final Activity activity) {
        if (BuildConfig.DEBUG) {
            LogUtil.d(this, activity.getLocalClassName() + ".onActivityPaused");
        }
    }

    @Override
    public void onActivityStopped(final Activity activity) {
        if (BuildConfig.DEBUG) {
            LogUtil.d(this, activity.getLocalClassName() + ".onActivityStopped");
        }
    }

    @Override
    public void onActivitySaveInstanceState(final Activity activity, final Bundle outState) {
        if (BuildConfig.DEBUG) {
            LogUtil.d(this, activity.getLocalClassName() + ".onActivitySaveInstanceState");
        }
    }

    @Override
    public void onActivityDestroyed(final Activity activity) {
        if (BuildConfig.DEBUG) {
            LogUtil.d(this, activity.getLocalClassName() + ".onActivityDestroyed");
        }
        ActivityController.INSTANCE.removeActivity(activity);
    }

    /**
     * 初始化activity打开时间
     */
    private void initActivityUseTime(final Activity activity) {
        if (activity == null || activity.getIntent() == null || activity.getIntent().getExtras() == null) {
            return;
        }


    }


}
